package com.mofang.powerdekorhelper.persenter;

import com.mofang.powerdekorhelper.base.BasePresent;
import com.mofang.powerdekorhelper.model.ResultMessage3;
import com.mofang.powerdekorhelper.utils.Constants;
import com.mofang.powerdekorhelper.utils.http.InitRetrofit;
import com.mofang.powerdekorhelper.utils.http.RetrofitSerives;
import com.mofang.powerdekorhelper.view.ResetPassWordView;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by luofei on 2017/8/18 0018.
 */

public class ResetPassWordPresenter extends BasePresent<ResetPassWordView> {

    public void getResetPassWord(String account, String passWord) {

        JSONObject object = new JSONObject();
        try {
            object.put("account", account);
            object.put("password", passWord);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        String requestStr = object.toString();

        RetrofitSerives retrofitSerives = InitRetrofit.getInstance().getRetrofit("http://www.kaolaj.com/shop-web/app/");

        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), requestStr);

        Call<ResultMessage3> call = retrofitSerives.getResetPassword(body);

        call.enqueue(new Callback<ResultMessage3>() {

            @Override
            public void onResponse(Call<ResultMessage3> call, Response<ResultMessage3> response) {
                if (response.isSuccessful()) {
                    view.setResetPassWord(response.body());
                } else {
                    view.onError(Constants.REQUEST_ERROR_INFO);
                }
            }

            @Override
            public void onFailure(Call<ResultMessage3> call, Throwable t) {
                view.onError(Constants.REQUEST_ERROR_INFO);
            }
        });

    }

    @Override
    public void stopRequest() {

    }
}
